package PTA3.ti5;

import java.util.Scanner;
import java.util.*;


/**
 * @author Lenovo
 */

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n1 = sc.nextInt();
        PersonOverride[] persons1 = new PersonOverride[n1];
        for (int i = 0; i < n1; i++) {
            persons1[i] = new PersonOverride();
        }

        int n2 = sc.nextInt();
        PersonOverride[] persons2 = new PersonOverride[n2];
        int count = 0;

        for (int i = 0; i < n2; i++) {
            String name = sc.next();
            int age = sc.nextInt();
            boolean gender = sc.nextBoolean();
            PersonOverride person = new PersonOverride(name, age, gender);
            Boolean flag = false;
            for (int j = 0; j < count; ++j) {
                if (persons2[j].equals(person)) {
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                persons2[count++] = person;
            }
        }
        for (PersonOverride person : persons1) {
            System.out.println(person);
        }
        for (int i = 0; i < count; ++i) {
            System.out.println(persons2[i]);
        }
        System.out.println(count);
        System.out.println(Arrays.toString(PersonOverride.class.getConstructors()));
        sc.close();
    }
}

class PersonOverride {
    private String name;
    private int age;
    private boolean gender;

    public PersonOverride() {
        this("default", 1, true);
    }

    public PersonOverride(String name, int age, boolean gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        PersonOverride that = (PersonOverride) obj;
        return age == that.age &&
                gender == that.gender &&
                name.equals(that.name);
    }

    @Override
    public String toString() {
        return name + "-" + age + "-" + gender;
    }
}